﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace School.Pages.UserControls
{
    public partial class CampusPackage : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
                FillControls();
        }
        private void FillControls()
        {
            ddlCampus.DataSource = School.Uniform.PayOrder.AllCampus();
            ddlCampus.DataBind();
       }
        private void ddlBind(DropDownList ddl)
        {
            ddl.Items.Clear();
            ddl.Items.Insert(0, new ListItem("اختيار", "0"));
            ddl.DataBind();
        }
        private void ddlBind(ListBox lbx)
        {
            lbx.Items.Clear();
            lbx.Items.Insert(0, new ListItem("الكل", "0"));
            lbx.DataBind();
        }
       
        protected void ddlCertificate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlCertificate.SelectedValue != "0")
            {
                ddlStadge.DataSource = School.Uniform.PayOrder.GetStadgeByCertificate(int.Parse(ddlCertificate.SelectedValue));
                ddlBind(ddlStadge);
            }
          
        }
        protected void ddlStadge_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlStadge.SelectedValue != "0")
            {
                ddlGrade.DataSource = School.Uniform.PayOrder.GetGradeByStadge(int.Parse(ddlStadge.SelectedValue));
                ddlBind(ddlGrade);
            }
            
        }
        public string CampusId { 
            get
            {
                if (!string.IsNullOrEmpty(ddlCampus.SelectedValue))
                    return ddlCampus.SelectedValue;
                else
                    return "0";
            }
            set
            {
               // ddlBind(ddlCampus);
                ddlCampus.SelectedValue = value;
            }
        }
        public string CertificateId
        {
            get
            {
                if(!string.IsNullOrEmpty(ddlCertificate.SelectedValue))
                   return ddlCertificate.SelectedValue;
                else
                    return "0";
            }
            set
            {
                ddlCertificate.DataSource = School.Uniform.PayOrder.GetCertificateByCamp(int.Parse(ddlCampus.SelectedValue));
                ddlBind(ddlCertificate);
                ddlCertificate.SelectedValue = value;
            }
        }
        public string StageId
        {
            get
            {
                if (!string.IsNullOrEmpty(ddlStadge.SelectedValue))
                    return ddlStadge.SelectedValue;
                else
                    return "0";
            }
            set
            {
                ddlStadge.DataSource = School.Uniform.PayOrder.GetStadgeByCertificate(int.Parse(ddlCertificate.SelectedValue));
                ddlBind(ddlStadge);
                ddlStadge.SelectedValue = value;
            }
        }
        public string GradeId
        {
            get
            {
                if (!string.IsNullOrEmpty(ddlGrade.SelectedValue))
                    return ddlGrade.SelectedValue;
                else
                    return "0";
            }
            set
            {
                ddlGrade.DataSource = School.Uniform.PayOrder.GetGradeByStadge(int.Parse(ddlStadge.SelectedValue));
                ddlBind(ddlGrade);
                ddlGrade.SelectedValue = value;
            }
        }
        protected void ddlCampus_TextChanged(object sender, EventArgs e)
        {
            if (ddlCampus.SelectedValue != "0")
            {
             
                ddlCertificate.DataSource = School.Uniform.PayOrder.GetCertificateByCamp(int.Parse(ddlCampus.SelectedValue));
                ddlBind(ddlCertificate);
            }
        }

       

        

       

    }
}